﻿using System;
using System.Configuration;
using XrmLibrary.Enums;

namespace XrmLibrary.ConfigFile
{
    public class XrmLibraryConfigSection : ConfigurationSection
    {
        private const String CrmServiceConfigurationsName = "crmServiceConfigurations";
        [ConfigurationProperty(CrmServiceConfigurationsName)]
        public CrmServiceConfigurationsCollection CrmServiceConfigurations
        {
            get { return (CrmServiceConfigurationsCollection) base[CrmServiceConfigurationsName]; }
        }

        private const String AdapterConfigurationsName = "adapterConfigurations";
        [ConfigurationProperty(AdapterConfigurationsName)]
        public AdapterConfigurationsCollection AdapterConfigurations
        {
            get { return (AdapterConfigurationsCollection) base[AdapterConfigurationsName]; }
        }

        private const String CredentialStoreName = "credentialStore";
        [ConfigurationProperty(CredentialStoreName, DefaultValue="config", IsRequired = false, IsKey = false)]
        public CredentialStoreType CredentialStore
        {
            get { return (CredentialStoreType) this[CredentialStoreName]; }
            set { this[CredentialStoreName] = value; }
        }

        private const String ServicePoolSizeName = "servicePoolSize";
        [ConfigurationProperty(ServicePoolSizeName, DefaultValue="0", IsRequired = false, IsKey = false)]
        public Int32 ServicePoolSize
        {
            get { return (Int32) this[ServicePoolSizeName]; }
            set { this[ServicePoolSizeName] = value; }
        }

        private const String ServicePoolRefreshInMillisecondsName = "servicePoolRefreshInMilliseconds";
        [ConfigurationProperty(ServicePoolRefreshInMillisecondsName, DefaultValue = "600000", IsRequired = false, IsKey = false)]
        public Int32 ServicePoolRefreshInMilliseconds
        {
            get { return (Int32)this[ServicePoolRefreshInMillisecondsName]; }
            set { this[ServicePoolRefreshInMillisecondsName] = value; }
        }

        private const String AppNameName = "appName";
        [ConfigurationProperty(AppNameName, DefaultValue = "", IsRequired = false, IsKey = false)]
        public String AppName
        {
            get { return (String)this[AppNameName]; }
            set { this[AppNameName] = value; }
        }

        private const String ConnectionStringName = "connectionString";
        [ConfigurationProperty(ConnectionStringName, DefaultValue = "", IsRequired = false, IsKey = false)]
        public String ConnectionString
        {
            get { return (String)this[ConnectionStringName]; }
            set { this[ConnectionStringName] = value; }
        }
    }
}
